package io.gitee.zhucan123.core.infrastructure.exception.advice;

import org.apache.commons.lang3.NotImplementedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author guodu
 * @date 2019/11/5
 */
@RestControllerAdvice
public class NotImplementedExceptionHandler {

  @ExceptionHandler(NotImplementedException.class)
  @ResponseStatus(HttpStatus.NOT_IMPLEMENTED)
  public ErrorDTO handlerNotImplementedException(HttpServletRequest req, NotImplementedException e) {
    String errorURL = req.getRequestURL().toString();
    return new ErrorDTO(e.getMessage(), HttpStatus.NOT_IMPLEMENTED.value(), errorURL);
  }

}
